'''文件操作'''
# f =open("a.txt",'w',encoding="utf-8")
# f.write("天净沙·秋思\n作者：马致远\n枯藤老树昏鸦，\n小桥流水人家，\n古道西风瘦马。\n夕阳西下，\n断肠人在天涯。\n")
# f.flush()
# f.close()
#
# f=open("a.txt",'r',encoding="utf-8")
# for i in f:
#     print(i,end=' ')
# f.close()

# f=open("a.txt",'rb')
# # 二进制读取文件
# data=f.read()
# print(data)
# f.close()
# print('_______________')
#
# f=open("a.txt",'rb')
# # 二进制读取文件
# data=f.read()
# data=data.decode('utf-8')
# print(data)
# f.close()
# print('_______________')
# f=open("a.txt",'a',encoding="utf-8")
# # 二进制读取文件
# f.write("------------------------\n")
# f.write("aaa天净沙·秋思\naaa作者：马致远\naa枯藤老树昏鸦，\na小桥流水人家，\na古道西风瘦马。\na夕阳西下，\na断肠人在天涯。\n")
# print(data)
# f.close()
#
# import os
# f1=open("a.txt",'r',encoding="utf-8")
# f2=open("b.txt",'w',encoding="utf-8")
# for i in f1:
#     if "a" in i:
#         y=i.replace("a","000")
#         f2.write(y)
# f1.close()
# f2.close()
# os.renames("a.txt","b.txt")
# os.remove("b.txt")
import os
with open("a.txt",'r',encoding="utf-8") as f1,\
        open("b.txt",'w',encoding="utf-8") as f2:
    f1.seek(0)
    for i in f1:
        if "AF" in i:
            i = i.replace("AF", "0")
        elif '，' in i:
            i = i.replace("，", "。")
        f2.write(i)
os.remove("a.txt")
os.renames("b.txt","a.txt")

# 字符串转二进制方式一
a ='sdagdfsdfsd'.encode("gbk")
print(a)
c ='fksdfjsmsdlpl'
# 字符串转方式二
b =bytes(c,encoding='gbk')
print(b)
